package com.winbomb.simulife.impl.jobs;

import com.winbomb.simulife.HonorType;
import com.winbomb.simulife.Master;
import com.winbomb.simulife.World;
import com.winbomb.simulife.base.JobTitle;
import com.winbomb.simulife.impl.BaseJob;

public class MicrogleJob extends BaseJob {

	private static final int[] EXPERIENCE_GRID = new int[] { 30, 100, 200, 500, 1000, 2000, 5000,
			10000, 20000, 50000, 100000, 200000, 500000 };

	private static final int[] SALARY_GRID = new int[] { 30, 100, 200, 500, 1000, 2000, 5000,
			10000, 20000, 50000, 100000, 200000, 500000 };

	public MicrogleJob(World world) {
		super(world);
	}

	@Override
	public String getCompanyName() {
		return "微谷软件有限责任公司";
	}

	@Override
	public int getStress() {
		return 80;
	}

	@Override
	public boolean apply() {
		return true;
	}

	@Override
	public boolean offer() {
		Master master = world.getMaster();

		// if (!master.hasHonor(HonorType.HN_YP_APPLY) || master.getAbility("")
		// < 80) {
		// return false;
		// }

		int workExp = master.getWorkExperience();
		int level = getLevelByExp(workExp);
		title = getTitleByLevel(level);
		salary = getSalaryByLevel(level);

		return true;
	}

	private int getLevelByExp(int workExp) {
		int level = 0;
		for (int exp : EXPERIENCE_GRID) {
			if (workExp < exp) {
				break;
			}
			level++;
		}

		return level;
	}

	private JobTitle getTitleByLevel(int level) {

		for (JobTitle title : JobTitle.values()) {
			if (title.ordinal() == level) {
				return title;
			}
		}

		return JobTitle.CEO;
	}

	private int getSalaryByLevel(int level) {

		if (level <= 0) {
			return SALARY_GRID[0];
		}

		if (level >= SALARY_GRID.length) {
			return SALARY_GRID[SALARY_GRID.length - 1];
		}

		return SALARY_GRID[level - 1];
	}

}
